from manimlib import *
import sys

sys.path.append("../..")
from customized import *
from numpy import flip, insert

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'


class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x = ValueTracker(50)
        r = 5
        diam = CustomizedLine(LEFT * r, RIGHT * r).shift(DOWN * r / 2)
        o = diam.get_center()
        arc = CustomizedArc(0, PI, radius=r, arc_center=o)
        p = diam.point_from_proportion(0.3)
        arc90 = CustomizedArc(x.get_value() * DEGREES, PI / 2, radius=r, arc_center=o)
        m, n = arc90.get_boundary_point(DL), arc90.get_boundary_point(DR)
        square_m = CustomizedSquare(m[1] + r / 2).set_fill(LV, 1).next_to(m, DR, buff=0)
        square_n = CustomizedSquare(n[1] + r / 2).set_fill(JH, 1).next_to(n, DL, buff=0)
        b10 = CustomizedBrace(diam, DOWN)
        self.add(diam, arc, square_m, square_n, b10,
                 CustomizedTex('10').next_to(b10, DOWN))
        self.wait()

class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x = ValueTracker(50)
        r = 5
        diam = CustomizedLine(LEFT * r, RIGHT * r).shift(DOWN * r / 2)
        o = diam.get_center()
        arc = CustomizedArc(0, PI, radius=r, arc_center=o)
        p = diam.point_from_proportion(0.3)
        arc90 = CustomizedArc(x.get_value() * DEGREES, PI / 2, radius=r, arc_center=o)
        m, n = arc90.get_boundary_point(DL), arc90.get_boundary_point(DR)
        square_m, square_n = CustomizedSquare(m[1] + r / 2).set_fill(LV, 1).next_to(m, DR, buff=0), CustomizedSquare(
            n[1] + r / 2).set_fill(JH, 1).next_to(n, DL, buff=0)
        self.add(diam, arc, square_m, square_n)
        # p2
        p = m + DR * (m[1] + r / 2)
        a, b = square_m.get_boundary_point(UL), square_n.get_boundary_point(UR)
        ab, pa, pb = CustomizedLine(a, b), CustomizedLine(p, a), CustomizedLine(p, b)
        self.add(ab, pa, pb,
                 CustomizedTex('P').next_to(p, DOWN),
                 CustomizedTex('A').next_to(a, UL),
                 CustomizedTex('B').next_to(b, UR),
                 CustomizedTex('x').next_to(square_m, DOWN),
                 CustomizedTex('y').next_to(square_n, DOWN),
                 )
        self.wait()


class p3(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        # x^2+y^2=r^2 6,8,10
        x = ValueTracker(50)
        r = 3
        diam = CustomizedLine(LEFT * r, RIGHT * r)
        o = diam.get_center()
        arc = CustomizedArc(0, PI, radius=r, arc_center=o)
        p = diam.point_from_proportion(0.3)
        arc90 = CustomizedArc(x.get_value() * DEGREES, PI / 2, radius=r, arc_center=o)
        m, n = arc90.get_boundary_point(DL), arc90.get_boundary_point(DR)
        square_m, square_n = CustomizedSquare(m[1]).set_fill(LV, 1).next_to(m, DR, buff=0), CustomizedSquare(
            n[1]).set_fill(JH, 1).next_to(n, DL, buff=0)
        # p2
        p = m + DR * (m[1])
        a, b = square_m.get_boundary_point(UL), square_n.get_boundary_point(UR)
        pa, pb = CustomizedLine(p, a), CustomizedLine(p, b)
        up = VGroup(diam, arc, square_m, square_n, pa, pb)
        self.add(up, up.copy().rotate(PI, [1, 0, 0], about_point=ORIGIN), CustomizedDot(o), CustomizedLine(o, a),
                 CustomizedLine(o, b), CustomizedLine(a, b),
                 CustomizedTex('O').next_to(o, DR),
                 CustomizedTex('A').next_to(a, UL),
                 CustomizedTex('B').next_to(b, UR),
                 CustomizedTex('A^\prime').next_to(a, DL).shift(DOWN * m[1] * 2),
                 CustomizedTex('B^\prime').next_to(b, DR).shift(DOWN * n[1] * 2),
                 )
        self.wait()
